﻿Ext.define('Entidades', {
    extend: 'ABMBase',
    Title: 'Formulario ABM Entidad',
    Model: 'Model.Entidad',
    defaultPropertySort: 'nombre',
    listeners: {
        Creando: function (rcd) {
            rcd.record.set('id_entidad', activeInstance.GetNum('ENT'));
        }
    },
    storePerfil: CreateForeignStore('storePerfil', 'Model.Perfil'),
    storeCategEnt: CreateForeignStore('storeCategEnt', 'Model.CategEnt'),
    WindowPanel: [{
        xtype: 'fieldset',
        title: 'General',
        collapsible: true,
        items: [{
            xtype: 'textfield',
            fieldLabel: 'Identificador',
            name: 'id_entidad',
            maxLength: 10,
            isPrimaryKey: true,
            enforceMaxLength: true,
            allowBlank: false
        }, {
            xtype: 'combobox',
            fieldLabel: 'Perfil',
            queryMode: 'local',
            displayField: 'descripcion',
            valueField: 'id_perfil',
            editable: true,
            forceSelection: true,
            store: Ext.StoreMgr.get('storePerfil'),
            allowBlank: false,
            name: 'id_perfil'
        }, {
            xtype: 'combobox',
            fieldLabel: 'Categoría de Entidad',
            queryMode: 'local',
            displayField: 'descripcion',
            valueField: 'id_categ_entidad',
            editable: true,
            forceSelection: true,
            store: Ext.StoreMgr.get('storeCategEnt'),
            allowBlank: false,
            name: 'id_categ_entidad'
        }, {
            xtype: 'textfield',
            fieldLabel: 'Nombre',
            name: 'nombre',
            maxLength: 50,
            enforceMaxLength: true,
            allowBlank: false
        }, {
            xtype: 'textfield',
            fieldLabel: 'Contacto',
            name: 'contacto',
            maxLength: 50,
            enforceMaxLength: true,
            allowBlank: false
        }]
    }, { xtype: 'fieldset',
        title: 'Domicilio',
        collapsible: true,
        items: [{
            xtype: 'container',
            frame: true,
            layout: 'column',
            items: [{
                xtype: 'fieldset',
                columnWidth: 0.5,
                border: false,
                items: [{
                    xtype: 'textfield',
                    fieldLabel: 'Domicilio',
                    name: 'domicilio',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Provincia',
                    name: 'provincia',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Teléfono',
                    name: 'tel',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Email',
                    name: 'email',
                    vtype: 'email',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }]
            }, {
                xtype: 'fieldset',
                columnWidth: 0.5,
                border: false,
                items: [{
                    xtype: 'textfield',
                    fieldLabel: 'Codigo Postal',
                    name: 'codpos',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Localidad',
                    name: 'localidad',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: false
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Fax',
                    name: 'fax',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: true
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Web Site',
                    name: 'website',
                    vtype: 'url',
                    maxLength: 50,
                    enforceMaxLength: true,
                    allowBlank: true
                }]
            }]
        }]
    }],
    Columns: [
            { text: 'Identificador', dataIndex: 'id_entidad', filter: true },
            {
                text: 'Perfil',
                dataIndex: 'id_perfil',
                filter: CreateListFilter('descripcion', 'id_perfil', 'storePerfil'),
                renderer: ForeignStoreRenderer('storePerfil', 'descripcion')
            },
            {
                text: 'Categoría Entidad',
                dataIndex: 'id_categ_entidad',
                filter: CreateListFilter('descripcion', 'id_categ_entidad', 'storeCategEnt'),
                renderer: ForeignStoreRenderer('storeCategEnt', 'descripcion')
            },
            { text: 'Nombre', dataIndex: 'nombre', filter: true },
            { text: 'Domicilio', dataIndex: 'domicilio', filter: true },
            { text: 'CP', dataIndex: 'codpos', filter: true },
            { text: 'Localidad', dataIndex: 'localidad', filter: true },
            { text: 'Provincia', dataIndex: 'provincia', filter: true },
            { text: 'Tel', dataIndex: 'tel', filter: true },
            { text: 'Fax', dataIndex: 'fax', filter: true },
            { text: 'Email', dataIndex: 'email', filter: true },
            { text: 'Website', dataIndex: 'website', filter: true },
            { text: 'Contacto', dataIndex: 'contacto', filter: true }
        ]
});
